package com.littleken.sellproject.service;

import com.littleken.sellproject.enums.ResultEnum;
import com.littleken.sellproject.exception.SellException;
import com.littleken.sellproject.utils.JsonData;
import com.littleken.sellproject.dao.ProductCategoryMapper;
import com.littleken.sellproject.model.ProductCategory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品种类service
 */
@Service
@Slf4j
public class ProductCategoryService {

    @Resource
    private ProductCategoryMapper mapper;

    public ProductCategory findOne(Integer catrgoryId){
        return mapper.findById(catrgoryId).get();
    }

    public List<ProductCategory> findAll(){
        return mapper.findAll();
    }

    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList){
        return  mapper.findByCategoryTypeIn(categoryTypeList);
    }


    public ProductCategory save(ProductCategory productCategory) {
        //todo: 校验操作
        return  mapper.save(productCategory);
    }

    public ProductCategory updaete(ProductCategory productCategory){
        return  mapper.save(productCategory);
    }

    public ProductCategory updaete(Integer updateId,ProductCategory productCategory){
        if(updateId != productCategory.getCategoryId()){
            throw new SellException(ResultEnum.ERROR_UPDATE_BYID);
        }
        return  mapper.save(productCategory);
    }

}
